const router = require('koa-router')()
const { getToken, Deleteurl, DeleteFileUrl } = require('../../config/databaseapi.js')

// 删除帖子接口
router.post('/deletetopic', async (ctx) => {
  console.log('调用删除帖子接口')
  console.log(ctx.request.body);
  // 先删除云存储里面的帖子封面，再删除云数据库记录
  const fileid_list = [ctx.request.body.pic]
  const res = await new getToken().posteve3(DeleteFileUrl, fileid_list);
  if (res.errcode === 0) {
    const res = await new getToken().posteve(Deleteurl, `db.collection("topic").where({_id:"${ctx.request.body._id}"}).remove()`);
    if (res.errcode === 0) {
      ctx.body = { msg: "删除成功", status: 1 };
    } else {
      ctx.body = { msg: "删除失败", status: 0 };
    }
  }
})

module.exports = router.routes()